package com.chixing.controller;

import com.chixing.commons.ServerResponse;
import com.chixing.commons.TokenUtil;
import com.chixing.pojo.LoginPerson;
import com.chixing.service.ICompanyDetailService;
import com.chixing.service.IJobDetailService;
import com.chixing.service.IPersonCenterService;
import com.chixing.service.IPersonFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *  * ////////////////////////////////////////////////////////////////////
 *  * //                          _ooOoo_                               //
 *  * //                         o8888888o                              //
 *  * //                         88" . "88                              //
 *  * //                         (| ^_^ |)                              //
 *  * //                         O\  =  /O                              //
 *  * //                      ____/`---'\____                           //
 *  * //                    .'  \\|     |//  `.                         //
 *  * //                   /  \\|||  :  |||//  \                        //
 *  * //                  /  _||||| -:- |||||-  \                       //
 *  * //                  |   | \\\  -  /// |   |                       //
 *  * //                  | \_|  ''\---/''  |   |                       //
 *  * //                  \  .-\__  `-`  ___/-. /                       //
 *  * //                ___`. .'  /--.--\  `. . ___                     //
 *  * //              ."" '<  `.___\_<|>_/___.'  >'"".                  //
 *  * //            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
 *  * //            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
 *  * //      ========`-.____`-.___\_____/___.-`____.-'========         //
 *  * //                           `=---='                              //
 *  * //      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
 *  * //            佛祖保佑       永不宕机      永无BUG                　 //
 *  * ////////////////////////////////////////////////////////////////////
 */
@RestController
public class IndexController {
    @Autowired
    private ICompanyDetailService companyDetailService;

    @Autowired
    private IJobDetailService jobDetailService;

    @Autowired
    private IPersonCenterService personCenterService;

    /**ces */

    //    用户登录加载用户数据
    @GetMapping("loginData")
    public ServerResponse loadLoginData(HttpServletRequest request) {
        //登陆验证中获取token
        String token = request.getHeader("token");
        System.out.println("用户的token=>" + token);
        LoginPerson loginPerson = null;
        ServerResponse result=null;
        if (token != null) {
            loginPerson = TokenUtil.parseToken(token);
            result = personCenterService.getByPersonal(loginPerson.getPersonId());

        }
        Map<String,Object> map = new HashMap<>();
        map.put("loginPerson",result.getData());
        return ServerResponse.success("success",map);
    }


    @GetMapping("hotJobDetailList")
    public ServerResponse loadhotJobListData(){
        ServerResponse hotJobList = jobDetailService.getJobAndCompany();
        Map<String,Object> map = new HashMap<>();
        map.put("hotJobList",hotJobList);
        return ServerResponse.success("success",map);
    }



    @GetMapping("hostCompanyList")
    public ServerResponse loadhstCompanyListData(){
        ServerResponse hostCompanyList = companyDetailService.getCompany();
        Map<String, Object> map = new HashMap<>();
        map.put("hostCompanyList",hostCompanyList);
        return ServerResponse.success("success",map);
    }
}
